package java111_2;

import java.util.Scanner;

public class Day40 {
    //https://ac.nowcoder.com/acm/problem/255195
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.next();
        boolean[] flag = new boolean[26];
        int ret = Integer.MAX_VALUE;
        for(int i = 0; i < str.length(); i++){
            int res = 0;
            if(!flag[str.charAt(i) - 'a']){
                for(int j = 0; j < str.length(); j++){
                    int min = Math.abs(str.charAt(i) - str.charAt(j));
                    res += Math.min(min, 26-min);
                    flag[str.charAt(i) - 'a'] = true;
                }
            }
            if(res != 0){
                ret = Math.min(res, ret);
            }
        }
        System.out.println(ret == Integer.MAX_VALUE ? 0 : ret);
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.next();
        int[] arr = new int[26];
        for(int i = 0; i < str.length(); i++){
            arr[str.charAt(i)-'a']++;
        }
        int res = Integer.MAX_VALUE;
        for(char c = 'a'; c <= 'z'; c++){
            int tmp = 0;
            for(int j = 0; j < str.length(); j++){
                tmp += Math.min(26 - Math.abs(str.charAt(j)-c), Math.abs(str.charAt(j)-c));
            }
            res = Math.min(res, tmp);
        }
        System.out.print(res);
    }

}
